<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue中多个元素或组件的过滤</title>
    <script src="../vue.js"></script> 
   
    <style>
      .v-enter, .v-leave-to {
          opacity: 0;
      }
      .v-enter-active, .v-leave-active {
          transition: opacity 1s；
      }
    </style>
</head>
<body>
    <div id="root"> 
      
        <!-- 动画钩子  入场动画 -->
        <transition
            mode="out-in"
        >
         <!-- 动画钩子  出场动画 -->
         
            <!-- <div v-if ="show" key="hello">hello world </div>
            <div v-else key="bye">hello world 2</div> -->
            <!-- <child v-if="show">hello world </child>
            <child-one v-else>hello world 2</child-one> -->

            <component :is="type"></component>
        </transition>       
        <button @click="handleBtnClick">change</button>
    </div>   
    
    <script>    

    //  组件过渡动画效果

    Vue.component('child',{
        template: '<div>child</div>'
    })

    Vue.component('child-one',{
        template: '<div>child-one</div>'
    })
       
    
        var root = new Vue({
            el: '#root',
            data: {
                // show: true
                type: 'child'
            },            
            methods: {
                handleBtnClick: function(){
                    // this.show = ! this.show
                    this.type = this.type === 'child' ? 'child-one' : 'child'
                }
            }        
           
        });
    </script>
</body>
</html>